﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Collections.ObjectModel;
using HigLabo.WindowsAzure.RestService.Extensions;

namespace HigLabo.WindowsAzure.RestService.ServiceManagement
{
    public class OperatingSystems
    {
        public static readonly String ElementName = "OperatingSystems";

        private Collection<OperatingSystem> _OperatingSystems = new Collection<OperatingSystem>();
        public IEnumerable<OperatingSystem> OperatingSystemList
        {
            get { foreach (var item in _OperatingSystems) { yield return item; } }
        }

        public OperatingSystems(XElement xml)
        {
            IEnumerable<XElement> els;
            if (xml == null)
            {
                throw new ArgumentNullException("xml");
            }
            /*OperatingSystems*/
            els = xml.ElementsByLocalName(OperatingSystem.ElementName);
            foreach (var item in els)
            {
                var add = new OperatingSystem(item);
                this._OperatingSystems.Add(add);
            }
        }
    }

    public class OperatingSystem
    {
        public static readonly String ElementName = "OperatingSystem";

        public String Version { get; private set; }
        public String Label { get; private set; }
        public Boolean? IsDefault { get; private set; }
        public Boolean? IsActive { get; private set; }
        public Int32? Family { get; private set; }
        public String FamilyLabel { get; private set; }

        public OperatingSystem(XElement xml)
        {
            if (xml == null)
            {
                throw new ArgumentNullException("xml");
            }
            /*OperatingSystem*/
            this.Version = xml.ValueOrEmpty("Version");
            this.Label = Base64Converter.From(xml.ValueOrEmpty("Label"));
            this.IsDefault = xml.ValueToBoolean("IsDefault");
            this.IsActive = xml.ValueToBoolean("IsActive");
            this.Family = xml.ValueToInt32("Family");
            this.FamilyLabel = Base64Converter.From(xml.ValueOrEmpty("FamilyLabel"));
        }
    }
}
